<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${package}.mapper.I${ClassName}Mapper">
    <#-- 映射结果集-->
    <resultMap id="BaseResultMap" type="${package}.entity.${ClassName}">
        <#list fieldList as field>
            <result property="${field.attrName}" column="${field.fieldName}"/>
        </#list>
    </resultMap>
    <!-- 通用查询结果列 -->
    <sql id="BaseColumnList">
        <#list fieldList as field>
            ${field.fieldName}<#if field_has_next>,</#if>
        </#list>
    </sql>
    <#-- 条件-->
    <sql id="ConditionSql">
        <where>
        <#list fieldList as field>
            <if test="${field.attrName} != null">
                and ${field.fieldName} = <#noparse>#{</#noparse>${field.attrName},jdbcType=${field.fieldType?upper_case}<#noparse>}</#noparse>
            </if>
        </#list>
            <if test="createStartDate != null">
                and create_time <![CDATA[ >= ]]> <#noparse>#{</#noparse>createStartDate,jdbcType=TIMESTAMP<#noparse>}</#noparse>
            </if>
            <if test="createEndDate != null">
                and create_time <![CDATA[ <= ]]> <#noparse>#{</#noparse>createEndDate,jdbcType=TIMESTAMP<#noparse>}</#noparse>
            </if>
            <if test="updateStartDate != null">
                and update_time <![CDATA[ >= ]]> <#noparse>#{</#noparse>updateStartDate,jdbcType=TIMESTAMP<#noparse>}</#noparse>
            </if>
            <if test="updateEndDate != null">
                and update_time <![CDATA[ <= ]]> <#noparse>#{</#noparse>updateEndDate,jdbcType=TIMESTAMP<#noparse>}</#noparse>
            </if>
        </where>
    </sql>
    <select id="select${ClassName}ByCondition" resultType="${package}.entity.${ClassName}" resultMap="BaseResultMap"
            parameterType="${package}.entity.query.${ClassName}Query">
        select
        <include refid="BaseColumnList"/>
        from ${tableName}
        <include refid="ConditionSql"/>
    </select>
</mapper>